<?php
namespace Modules\Warehouse\Http\Repositories;


use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Modules\Purchasing\Models\Supplier;
use Modules\Purchasing\Models\Supplierschedule;
use Illuminate\Support\Facades\DB;
use Catch\Exceptions\FailedException;
use Modules\Base\Service\BoxService;
use Modules\Purchasing\Models\Suppliernamedelivery;
use Modules\Purchasing\Models\Purchaseorder;
use Modules\Purchasing\Models\Purchaseorderschedule;
use App\Enums\BoxFrom;
use Modules\Purchasing\Models\Provisionalschedule;
use Modules\Purchasing\Models\Barcodeprinting;
use Modules\Warehouse\Models\Storagelocation;
use Modules\Warehouse\Models\Stash;


class StorageReget 
{
    /*
    检验单列表接口
    */
    public static function listtable($data = [])
    {
        return self::getBuildertable($data)->paginate($data['limit'] ?? 100);
    }

    /*
    检验id
    */
    public static function getBuildertable(array $data = []): Builder
    {
        $builder = Storagelocation::query();

        if (isset($data['warehousecode'])) {
            $builder->where('warehousecode',$data['warehousecode']);
        }

        if (isset($data['repositoryname'])) {
            $builder->where('repositoryname',$data['repositoryname']);
        }

        
        if (isset($data['remarks'])) {
            $builder->where('remarks',$data['remarks']);
        }
       
        if (isset($data['owning_id'])) {
            $builder->where('owning_id',$data['owning_id']);
        }

       

        
        if (isset($data['fnumber'])) {    
            $fnumber = Stash::select('fmaterial','fnumber','fname','id')->where('fnumber', $data['fnumber'])->first();
            if(!empty($fnumber)){
                $builder->where('owning_id',$fnumber['id']);
            }else {
                $builder->where('owning_id','');
            }
        }

 
      


        $builder->orderBy('id', 'desc');
        return $builder;
  
    }
    

   


}
